//
//  CPDScatterPlotViewController.m
//  CorePlotDemo
//
//  Created by Fahim Farook on 19/5/12.
//  Copyright 2012 RookSoft Pte. Ltd. All rights reserved.
//

#import "CPDScatterPlotViewController.h"
#import "DevicesTableViewController.h"
#import "UiManager.h"
#import "CPDConstants.h"
#import "CPDStockPriceStore.h"
#import "ILTranslucentView.h"
#import "ParserClass.h"
#import "loadingView.h"
#import "IIViewDeckController.h"
#import "LoginViewController.h"


#define kBgQueue dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
CPTFill *bandFill;
int state = 1;
int datePickerState = 0;
int arrState = 0;
int sensorState = 0;
NSInteger pickerCount;

NSString *deviceType;

NSInteger fromCount;
NSInteger toCount;

@implementation CPDScatterPlotViewController

@synthesize hostView = hostView_;
@synthesize sensorPicker;

-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        
        
    }
    return self;
}

-(void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - UIViewController lifecycle methods


-(void)viewDidLoad{
    

    [self.navigationController.navigationBar setHidden:YES];
      [self.tabBarController.tabBar setHidden:YES];
    
    ILTranslucentView *translucentView = [[ILTranslucentView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    
//    sensorPicker = [NSMutableArray arrayWithObjects:@"chamberSetPoint",@"highTemperatureLimit", @"lowTemperatureLimit", @"chamberTemperatureSensor", @"ambientSensor", @"condenserOutletSensor", @"heatexchangerTempSensor", @"evapInSensor", @"evapOutSensor", @"batterVoltage", @"acVoltage", @"highStage", nil];
    
    
    deviceType = [[ParserClass sharedItems] equipmentType];
    
    if ([deviceType isEqualToString:@"ultf_gold"] || [deviceType isEqualToString:@"ultf_silver"]) {
        
        sensorPicker = [NSMutableArray arrayWithObjects:@"Chamber Set Point",@"High Temperature Limit", @"Low Temperature Limit", @"Chamber Temperature Sensor", @"NTC Ambient Sensor", @"NTC Condenser Sensor", @"NTC Heat Exchanger 1", @"NTC Heat Exchanger 2", @"AC Voltage", nil];
        
    }else if ([deviceType isEqualToString:@"ultf_platinum"]){
        
        sensorPicker = [NSMutableArray arrayWithObjects:@"Chamber Set Point",@"High Temperature Limit", @"Low Temperature Limit", @"Chamber Temperature Sensor", @"Ambient Sensor", @"Condenser Outlet Sensor", @"Heat Exchanger Temperature Sensor", @"Evap In Sensor", @"Evap Out Sensor", @"Battery Voltage", @"AC Voltage", @"High Stage", nil];
        
        
    }else if ([deviceType isEqualToString:@"co2_incubator"]){
        
        sensorPicker = [NSMutableArray arrayWithObjects:@"temperatureSetPoint",@"co2SetPoint", @"O2 Set Point", @"High Temperature Limit", @"Low Temperature Limit", @"High Co2 Limit", @"Low Co2 Limit", @"High O2 Limit", @"Low O2 Limit", @"Low Rh Limit", @"Temperature Sensor", @"Co2 Sensor",@"O2 Sensor", @"Rh Sensor", nil];
        
        
    }else if ([deviceType isEqualToString:@"ecs-g2"]){
        
        sensorPicker = [NSMutableArray arrayWithObjects:@"Low Inflow Limit",@"High Downflow Limit", @"Low Downflow Limit", @"High Temperature Limit", @"Low Temperature Limit", @"High DC Voltage Limit", @"Low DC Voltage Limit", @"Inflow Sensor", @"Downflow Sensor", @"Temperature Sensor", @"DC Voltage", nil];
        
        
    }else if ([deviceType isEqualToString:@"ofa"] || [deviceType isEqualToString:@"ifa"] || [deviceType isEqualToString:@"ifc"] || [deviceType isEqualToString:@"ina"]){
        
        sensorPicker = [NSMutableArray arrayWithObjects:@"Chamber Set Point",@"High Temperature Limit", @"Low Temperature Limit", @"Chamber Temperature Sensor", nil];
    }
    
    if ([[[CPDStockPriceStore sharedInstance] devicesArrTimeData] count] == 0) {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:@"No data found" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
        
        [alertView show];
    }else{
    
    self.datePickerArr = [[CPDStockPriceStore sharedInstance] devicesArrTimeData];

    }
    self.lblSensor.text = [sensorPicker objectAtIndex:0];
    
    self.lblSensorIndicator.text = [sensorPicker objectAtIndex:0];
    
    self.lblFrom.text = [self.datePickerArr objectAtIndex:0];
    
    self.lblTo.text = [self.datePickerArr objectAtIndex:[self.datePickerArr count] - 1];
    
    fromCount = 0;
    
    toCount = [self.datePickerArr count] - 1;
    
    [[CPDStockPriceStore sharedInstance] devicesArrTimeFromDate:0 andToDate:[NSString stringWithFormat:@"%i",[self.datePickerArr count] - 1]];
    
    
//    [[CPDStockPriceStore sharedInstance] devicesArrTime:self.lblSensor.text];

    [self.pickerViewProp selectRow:4 inComponent:0 animated:YES];
    
    
    [self.viewFilters addSubview:translucentView];
    
    translucentView.translucentAlpha = 1;
    translucentView.translucentStyle = UIBarStyleDefault;
    translucentView.translucentTintColor = [UIColor colorWithRed:2/255.0 green:2/255.0 blue:2/255.0 alpha:1.0];
    translucentView.backgroundColor = [UIColor clearColor];
    
    
    [translucentView addSubview:self.viewFilterList];
    [translucentView addSubview:self.btnCancelCir];
    
}

-(void)viewWillAppear:(BOOL)animated{
    
   
    
}

-(void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    self.viewFilterList.layer.cornerRadius = 18;
    self.lblFrom.layer.cornerRadius = 6;
    self.lblSensor.layer.cornerRadius = 6;
    self.lblTo.layer.cornerRadius = 6;
    self.btnCancelProp.layer.cornerRadius = 6;
    self.btnDoneProp.layer.cornerRadius = 6;
    self.viewToolBar.layer.cornerRadius = 16;
    
    self.btnCancelDateProp.layer.cornerRadius = 6;
    self.btnDoneDateProp.layer.cornerRadius = 6;
    self.datepickerFromandTo.layer.cornerRadius = 16;
    self.btnDoneFilteringProp.layer.cornerRadius = 6;
    
    [[CPDStockPriceStore sharedInstance] devicesArr:self.lblSensor.text];
    [[CPDStockPriceStore sharedInstance] devicesArrTimeFromDate:0 andToDate:[NSString stringWithFormat:@"%i",[self.datePickerArr count] - 1]];
    
    NSLog(@"Label Test %@",self.lblSensor.text);
//    if ([self.lblSensor.text isEqualToString:@"chamberSetPoint"]) {
//        
//        NSLog(@"Test Graph 1");
//    }
//    }else if ([self.lblSensor.text isEqualToString:@"highTemperatureLimit"]){
//        
//        NSLog(@"Test Graph 2");
//        
//    }else if ([self.lblSensor.text isEqualToString:@"lowTemperatureLimit"]){
//        
//        NSLog(@"Test Graph 3");
//        
//    }else if ([self.lblSensor.text isEqualToString:@"chamberTemperatureSensor"]){
//        
//        NSLog(@"Test Graph 4");
//        
//    }else if ([self.lblSensor.text isEqualToString:@"ambientSensor"]){
//        
//        NSLog(@"Test Graph 5");
//        
//    }else if ([self.lblSensor.text isEqualToString:@"condenserOutletSensor"]){
//        
//        NSLog(@"Test Graph 6");
//        
//    }else if ([self.lblSensor.text isEqualToString:@"heatexchangerTempSensor"]){
//        
//        NSLog(@"Test Graph 7");
//        
//    }else if ([self.lblSensor.text isEqualToString:@"highevapInSensorTemperatureLimit"]){
//        
//        NSLog(@"Test Graph 8");
//        
//    }else if ([self.lblSensor.text isEqualToString:@"evapOutSensor"]){
//        
//        NSLog(@"Test Graph 9");
//        
//    }else if ([self.lblSensor.text isEqualToString:@"batterVoltage"]){
//        
//        NSLog(@"Test Graph 10");
//        
//    }else if ([self.lblSensor.text isEqualToString:@"acVoltage"]){
//        
//        NSLog(@"Test Graph 11");
//        
//    }else if ([self.lblSensor.text isEqualToString:@"highStage"]){
//        
//        NSLog(@"Test Graph 12");
//        
//    }
    
    //[[CPDStockPriceStore sharedInstance] devicesArr:@"condenserOutletSensor"];
    [self initPlot];
}


-(void)ReloadGraph{
    [self.hostView.hostedGraph reloadData];
}


#pragma mark - Chart behavior
-(void)initPlot {
    [self configureHost];
    [self configureGraph];
    [self configurePlots];
    [self configureAxes];
}

-(void)configureHost {
    
	self.hostView = [(CPTGraphHostingView *) [CPTGraphHostingView alloc] initWithFrame:self.test.bounds];
	self.hostView.allowPinchScaling = YES;
	[self.test addSubview:self.hostView];
}

-(void)configureGraph {
	// 1 - Create the graph
	CPTGraph *graph = [[CPTXYGraph alloc] initWithFrame:self.hostView.bounds];
	[graph applyTheme:[CPTTheme themeNamed:kCPTStocksTheme]];
	self.hostView.hostedGraph = graph;
    
	// 2 - Set graph title
	NSString *title = @"";
	graph.title = title;
	
    // 3 - Create and set text style
	CPTMutableTextStyle *titleStyle = [CPTMutableTextStyle textStyle];
	titleStyle.color = [CPTColor whiteColor];
	titleStyle.fontName = @"Helvetica-Bold";
	titleStyle.fontSize = 16.0f;
	graph.titleTextStyle = titleStyle;
	graph.titlePlotAreaFrameAnchor = CPTRectAnchorTop;
	graph.titleDisplacement = CGPointMake(0.0f, 10.0f);
	
    // 4 - Set padding for plot area
	[graph.plotAreaFrame setPaddingLeft:10.0f];
	[graph.plotAreaFrame setPaddingBottom:10.0f];
	
    // 5 - Enable user interactions for plot space
	CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *) graph.defaultPlotSpace;
	plotSpace.allowsUserInteraction = YES;
}

-(void)configurePlots {
	// 1 - Get graph and plot space

	CPTGraph *graph = self.hostView.hostedGraph;
	CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *) graph.defaultPlotSpace;
    
    // 2 - Create the three plots
	CPTScatterPlot *aaplPlot = [[CPTScatterPlot alloc] init];
	aaplPlot.dataSource = self;
	aaplPlot.identifier = CPDTickerSymbolAAPL;
	CPTColor *aaplColor = [CPTColor redColor];
	[graph addPlot:aaplPlot toPlotSpace:plotSpace];
    
    //	CPTScatterPlot *googPlot = [[CPTScatterPlot alloc] init];
    //	googPlot.dataSource = self;
    //	googPlot.identifier = CPDTickerSymbolGOOG;
    //	CPTColor *googColor = [CPTColor greenColor];
    //	[graph addPlot:googPlot toPlotSpace:plotSpace];
	CPTScatterPlot *msftPlot = [[CPTScatterPlot alloc] init];
	msftPlot.dataSource = self;
	msftPlot.identifier = CPDTickerSymbolMSFT;
	CPTColor *msftColor = [CPTColor clearColor];
	[graph addPlot:msftPlot toPlotSpace:plotSpace];
    
    
	
    
    // 3 - Set up plot space Default Values
    
    
    deviceType = [[ParserClass sharedItems] equipmentType];
    
    if ([deviceType isEqualToString:@"ultf_gold"] || [deviceType isEqualToString:@"ultf_silver"]) {
        
        
        if ([self.lblSensor.text isEqualToString:@"Chamber Set Point"]) {
            
            plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-2) length:CPTDecimalFromInt(3000)];
            //Setup X-axis spaces
            plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-10)length:CPTDecimalFromInt(10)];
            
            
            plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-40) length:CPTDecimalFromInt(400)];
            plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(180)length:CPTDecimalFromInt(1000)];
            
        }else if ([self.lblSensor.text isEqualToString:@"High Temperature Limit"]){
            
            plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-2) length:CPTDecimalFromInt(3000)];
            //Setup X-axis spaces
            plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-10)length:CPTDecimalFromInt(10)];
            
            
            plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-200) length:CPTDecimalFromInt(500)];
            plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-90)length:CPTDecimalFromInt(1000)];
            
        }else if ([self.lblSensor.text isEqualToString:@"Low Temperature Limit"]){
            
            plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-2) length:CPTDecimalFromInt(3000)];
            //Setup X-axis spaces
            plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-10)length:CPTDecimalFromInt(10)];
            
            
            plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-200) length:CPTDecimalFromInt(500)];
            plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-90)length:CPTDecimalFromInt(1000)];
            
        }else if ([self.lblSensor.text isEqualToString:@"Chamber Temperature Sensor"]){
            
            plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-2) length:CPTDecimalFromInt(3000)];
            //Setup X-axis spaces
            plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-10)length:CPTDecimalFromInt(10)];
            
            
            plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-200) length:CPTDecimalFromInt(500)];
            plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-90)length:CPTDecimalFromInt(1000)];
            
        }else if ([self.lblSensor.text isEqualToString:@"NTC Ambient Sensor"]){
           
            plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-2) length:CPTDecimalFromInt(3000)];
            //Setup X-axis spaces
            plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-10)length:CPTDecimalFromInt(10)];
            plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-30) length:CPTDecimalFromInt(140)];
            plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-30)length:CPTDecimalFromInt(1000)];
            
        }else if ([self.lblSensor.text isEqualToString:@"NTC Condenser Sensor"]){

            plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-2) length:CPTDecimalFromInt(3000)];
            //Setup X-axis spaces
            plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-10)length:CPTDecimalFromInt(10)];
            plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-30) length:CPTDecimalFromInt(140)];
            plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-30)length:CPTDecimalFromInt(1000)];
            
        }else if ([self.lblSensor.text isEqualToString:@"NTC Heat Exchanger 1"]){
            
            plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-2) length:CPTDecimalFromInt(3000)];
            //Setup X-axis spaces
            plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-10)length:CPTDecimalFromInt(10)];
            
            
            plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-200) length:CPTDecimalFromInt(500)];
            plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-90)length:CPTDecimalFromInt(1000)];
            
        }else if ([self.lblSensor.text isEqualToString:@"NTC Heat Exchanger 2"]){
            
            plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-2) length:CPTDecimalFromInt(3000)];
            //Setup X-axis spaces
            plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-10)length:CPTDecimalFromInt(10)];
            
            
            plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-200) length:CPTDecimalFromInt(500)];
            plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-90)length:CPTDecimalFromInt(1000)];
        
        }else if ([self.lblSensor.text isEqualToString:@"AC Voltage"]){
            
            plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-2) length:CPTDecimalFromInt(3000)];
            //Setup X-axis spaces
            plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-10)length:CPTDecimalFromInt(10)];
            plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-30) length:CPTDecimalFromInt(140)];
            plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-30)length:CPTDecimalFromInt(1000)];
            
        }
        
    }else if ([deviceType isEqualToString:@"ultf_platinum"]){
        
        if ([self.lblSensor.text isEqualToString:@"Chamber Set Point"]) {
            
            plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-2) length:CPTDecimalFromInt(3000)];
            //Setup X-axis spaces
            plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-10)length:CPTDecimalFromInt(10)];
            
            
            plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-200) length:CPTDecimalFromInt(500)];
            plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-90)length:CPTDecimalFromInt(1000)];
            
        }else if ([self.lblSensor.text isEqualToString:@"High Temperature Limit"]){
            
            plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-2) length:CPTDecimalFromInt(3000)];
            //Setup X-axis spaces
            plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-10)length:CPTDecimalFromInt(10)];
            
            
            plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-200) length:CPTDecimalFromInt(500)];
            plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-90)length:CPTDecimalFromInt(1000)];
            
        }else if ([self.lblSensor.text isEqualToString:@"Low Temperature Limit"]){
            
            plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-2) length:CPTDecimalFromInt(3000)];
            //Setup X-axis spaces
            plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-10)length:CPTDecimalFromInt(10)];
            
            
            plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-200) length:CPTDecimalFromInt(500)];
            plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-90)length:CPTDecimalFromInt(1000)];
            
        }else if ([self.lblSensor.text isEqualToString:@"Chamber Temperature Sensor"]){
            
            plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-2) length:CPTDecimalFromInt(3000)];
            //Setup X-axis spaces
            plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-10)length:CPTDecimalFromInt(10)];
            
            
            plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-200) length:CPTDecimalFromInt(500)];
            plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-90)length:CPTDecimalFromInt(1000)];
            
        }else if ([self.lblSensor.text isEqualToString:@"Ambient Sensor"]){
            
            plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-2) length:CPTDecimalFromInt(3000)];
            //Setup X-axis spaces
            plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-10)length:CPTDecimalFromInt(10)];
            plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-30) length:CPTDecimalFromInt(140)];
            plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-30)length:CPTDecimalFromInt(1000)];
            
        }else if ([self.lblSensor.text isEqualToString:@"Condenser Outlet Sensor"]){
            
            plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-2) length:CPTDecimalFromInt(3000)];
            //Setup X-axis spaces
            plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-10)length:CPTDecimalFromInt(10)];
            plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-30) length:CPTDecimalFromInt(140)];
            plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-30)length:CPTDecimalFromInt(1000)];
            
        }else if ([self.lblSensor.text isEqualToString:@"Heat Exchanger Temperature Sensor"]){
            
            plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-2) length:CPTDecimalFromInt(3000)];
            //Setup X-axis spaces
            plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-10)length:CPTDecimalFromInt(10)];
            
            
            plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-200) length:CPTDecimalFromInt(500)];
            plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-90)length:CPTDecimalFromInt(1000)];
            
        }else if ([self.lblSensor.text isEqualToString:@"Evap In Sensor"]){
            
            plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-2) length:CPTDecimalFromInt(3000)];
            //Setup X-axis spaces
            plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-10)length:CPTDecimalFromInt(10)];
            
            
            plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-200) length:CPTDecimalFromInt(500)];
            plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-90)length:CPTDecimalFromInt(1000)];
            
        }else if ([self.lblSensor.text isEqualToString:@"Evap Out Sensor"]){
            
            plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-2) length:CPTDecimalFromInt(3000)];
            //Setup X-axis spaces
            plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-10)length:CPTDecimalFromInt(10)];
            plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-30) length:CPTDecimalFromInt(140)];
            plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-30)length:CPTDecimalFromInt(1000)];
            
        }else if ([self.lblSensor.text isEqualToString:@"Battery Voltage"]){
            
            plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-2) length:CPTDecimalFromInt(3000)];
            //Setup X-axis spaces
            plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-10)length:CPTDecimalFromInt(10)];
            plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-30) length:CPTDecimalFromInt(140)];
            plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-30)length:CPTDecimalFromInt(1000)];
            
            
        }else if ([self.lblSensor.text isEqualToString:@"AC Voltage"]){
            
            
            plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-2) length:CPTDecimalFromInt(3000)];
            //Setup X-axis spaces
            plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-10)length:CPTDecimalFromInt(10)];
            
            
            plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-40) length:CPTDecimalFromInt(400)];
            plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(180)length:CPTDecimalFromInt(1000)];
            
            
        }else if ([self.lblSensor.text isEqualToString:@"High Stage"]){
            
            plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-2) length:CPTDecimalFromInt(3000)];
            //Setup X-axis spaces
            plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-10)length:CPTDecimalFromInt(10)];
            plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-30) length:CPTDecimalFromInt(140)];
            plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-30)length:CPTDecimalFromInt(1000)];
            
        }

        
    }else if ([deviceType isEqualToString:@"co2_incubator"]){
        
       
        
        if ([self.lblSensor.text isEqualToString:@"Temperature Set Point"]) {
            
            plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-2) length:CPTDecimalFromInt(3000)];
            //Setup X-axis spaces
            plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-10)length:CPTDecimalFromInt(10)];
            
            
            plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-40) length:CPTDecimalFromInt(400)];
            plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(180)length:CPTDecimalFromInt(1000)];
            
            
        }else if ([self.lblSensor.text isEqualToString:@"Co2 Set Point"]){
            
            plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-2) length:CPTDecimalFromInt(3000)];
            //Setup X-axis spaces
            plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-10)length:CPTDecimalFromInt(10)];
            
            
            plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-200) length:CPTDecimalFromInt(500)];
            plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-90)length:CPTDecimalFromInt(1000)];
            
            
        }else if ([self.lblSensor.text isEqualToString:@"O2 Set Point"]){
            
            plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-2) length:CPTDecimalFromInt(3000)];
            //Setup X-axis spaces
            plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-10)length:CPTDecimalFromInt(10)];
            
            
            plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-200) length:CPTDecimalFromInt(500)];
            plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-90)length:CPTDecimalFromInt(1000)];
            
        }else if ([self.lblSensor.text isEqualToString:@"High Temperature Limit"]){
            
            plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-2) length:CPTDecimalFromInt(3000)];
            //Setup X-axis spaces
            plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-10)length:CPTDecimalFromInt(10)];
            
            
            plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-200) length:CPTDecimalFromInt(500)];
            plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-90)length:CPTDecimalFromInt(1000)];
            
        }else if ([self.lblSensor.text isEqualToString:@"Low Temperature Limit"]){
            
            plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-2) length:CPTDecimalFromInt(3000)];
            //Setup X-axis spaces
            plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-10)length:CPTDecimalFromInt(10)];
            plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-30) length:CPTDecimalFromInt(140)];
            plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-30)length:CPTDecimalFromInt(1000)];
            
        }else if ([self.lblSensor.text isEqualToString:@"High Co2 Limit"]){
            
            plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-2) length:CPTDecimalFromInt(3000)];
            //Setup X-axis spaces
            plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-10)length:CPTDecimalFromInt(10)];
            plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-30) length:CPTDecimalFromInt(140)];
            plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-30)length:CPTDecimalFromInt(1000)];
            
        }else if ([self.lblSensor.text isEqualToString:@"Low Co2 Limit"]){
            
            plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-2) length:CPTDecimalFromInt(3000)];
            //Setup X-axis spaces
            plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-10)length:CPTDecimalFromInt(10)];
            
            
            plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-200) length:CPTDecimalFromInt(500)];
            plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-90)length:CPTDecimalFromInt(1000)];
            
        }else if ([self.lblSensor.text isEqualToString:@"High O2 Limit"]){
            
            plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-2) length:CPTDecimalFromInt(3000)];
            //Setup X-axis spaces
            plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-10)length:CPTDecimalFromInt(10)];
            
            
            plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-200) length:CPTDecimalFromInt(500)];
            plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-90)length:CPTDecimalFromInt(1000)];
            
        }else if ([self.lblSensor.text isEqualToString:@"Low O2 Limit"]){
            
            plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-2) length:CPTDecimalFromInt(3000)];
            //Setup X-axis spaces
            plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-10)length:CPTDecimalFromInt(10)];
            plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-30) length:CPTDecimalFromInt(140)];
            plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-30)length:CPTDecimalFromInt(1000)];
            
        }else if ([self.lblSensor.text isEqualToString:@"Low Rh Limit"]){
            
            plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-2) length:CPTDecimalFromInt(3000)];
            //Setup X-axis spaces
            plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-10)length:CPTDecimalFromInt(10)];
            plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-30) length:CPTDecimalFromInt(140)];
            plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-30)length:CPTDecimalFromInt(1000)];
            
            
        }else if ([self.lblSensor.text isEqualToString:@"Temperature Sensor"]){
            
        
            plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-2) length:CPTDecimalFromInt(3000)];
            //Setup X-axis spaces
            plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-10)length:CPTDecimalFromInt(10)];
            
            
            plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-40) length:CPTDecimalFromInt(400)];
            plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(180)length:CPTDecimalFromInt(1000)];
            
            
        }else if ([self.lblSensor.text isEqualToString:@"Co2 Sensor"]){
            
            
            
            plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-2) length:CPTDecimalFromInt(3000)];
            //Setup X-axis spaces
            plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-10)length:CPTDecimalFromInt(10)];
            plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-30) length:CPTDecimalFromInt(140)];
            plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-30)length:CPTDecimalFromInt(1000)];
            
        }else if ([self.lblSensor.text isEqualToString:@"O2 Sensor"]){
            
            plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-2) length:CPTDecimalFromInt(3000)];
            //Setup X-axis spaces
            plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-10)length:CPTDecimalFromInt(10)];
            plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-30) length:CPTDecimalFromInt(140)];
            plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-30)length:CPTDecimalFromInt(1000)];
            
        }else if ([self.lblSensor.text isEqualToString:@"Rh Sensor"]){
            
            
            plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-2) length:CPTDecimalFromInt(3000)];
            //Setup X-axis spaces
            plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-10)length:CPTDecimalFromInt(10)];
            plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-30) length:CPTDecimalFromInt(140)];
            plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-30)length:CPTDecimalFromInt(1000)];
            
        }

        
    }else if ([deviceType isEqualToString:@"ecs-g2"]){
        
        if ([self.lblSensor.text isEqualToString:@"Low Inflow Limit"]) {
            
            plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-2) length:CPTDecimalFromInt(3000)];
            //Setup X-axis spaces
            plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-10)length:CPTDecimalFromInt(10)];
            
            
            plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-40) length:CPTDecimalFromInt(400)];
            plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(180)length:CPTDecimalFromInt(1000)];
            
        }else if ([self.lblSensor.text isEqualToString:@"High Downflow Limit"]){
            
            plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-2) length:CPTDecimalFromInt(3000)];
            //Setup X-axis spaces
            plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-10)length:CPTDecimalFromInt(10)];
            
            
            plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-200) length:CPTDecimalFromInt(500)];
            plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-90)length:CPTDecimalFromInt(1000)];
            
        }else if ([self.lblSensor.text isEqualToString:@"Low Downflow Limit"]){
            
            plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-2) length:CPTDecimalFromInt(3000)];
            //Setup X-axis spaces
            plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-10)length:CPTDecimalFromInt(10)];
            
            
            plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-200) length:CPTDecimalFromInt(500)];
            plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-90)length:CPTDecimalFromInt(1000)];
            
        }else if ([self.lblSensor.text isEqualToString:@"High Temperature Limit"]){
            
            plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-2) length:CPTDecimalFromInt(3000)];
            //Setup X-axis spaces
            plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-10)length:CPTDecimalFromInt(10)];
            
            
            plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-200) length:CPTDecimalFromInt(500)];
            plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-90)length:CPTDecimalFromInt(1000)];
            
        }else if ([self.lblSensor.text isEqualToString:@"Low Temperature Limit"]){
            
            
            plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-2) length:CPTDecimalFromInt(3000)];
            //Setup X-axis spaces
            plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-10)length:CPTDecimalFromInt(10)];
            plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-30) length:CPTDecimalFromInt(140)];
            plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-30)length:CPTDecimalFromInt(1000)];
            
        }else if ([self.lblSensor.text isEqualToString:@"High DC Voltage Limit"]){
            
            
            plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-2) length:CPTDecimalFromInt(3000)];
            //Setup X-axis spaces
            plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-10)length:CPTDecimalFromInt(10)];
            plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-30) length:CPTDecimalFromInt(140)];
            plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-30)length:CPTDecimalFromInt(1000)];
            
        }else if ([self.lblSensor.text isEqualToString:@"Low DC Voltage Limit"]){
            
            plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-2) length:CPTDecimalFromInt(3000)];
            //Setup X-axis spaces
            plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-10)length:CPTDecimalFromInt(10)];
            
            
            plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-200) length:CPTDecimalFromInt(500)];
            plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-90)length:CPTDecimalFromInt(1000)];
            
        }else if ([self.lblSensor.text isEqualToString:@"Inflow Sensor"]){
           
            plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-2) length:CPTDecimalFromInt(3000)];
            //Setup X-axis spaces
            plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-10)length:CPTDecimalFromInt(10)];
            
            
            plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-200) length:CPTDecimalFromInt(500)];
            plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-90)length:CPTDecimalFromInt(1000)];
            
        }else if ([self.lblSensor.text isEqualToString:@"Downflow Sensor"]){
            
            plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-2) length:CPTDecimalFromInt(3000)];
            //Setup X-axis spaces
            plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-10)length:CPTDecimalFromInt(10)];
            plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-30) length:CPTDecimalFromInt(140)];
            plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-30)length:CPTDecimalFromInt(1000)];
            
        }else if ([self.lblSensor.text isEqualToString:@"Temperature Sensor"]){
            
            plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-2) length:CPTDecimalFromInt(3000)];
            //Setup X-axis spaces
            plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-10)length:CPTDecimalFromInt(10)];
            plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-30) length:CPTDecimalFromInt(140)];
            plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-30)length:CPTDecimalFromInt(1000)];
            
            
        }else if ([self.lblSensor.text isEqualToString:@"DC Voltage"]){
            
            
            plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-2) length:CPTDecimalFromInt(3000)];
            //Setup X-axis spaces
            plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-10)length:CPTDecimalFromInt(10)];
            
            
            plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-40) length:CPTDecimalFromInt(400)];
            plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(180)length:CPTDecimalFromInt(1000)];
            
            
        }
        
    }else if ([deviceType isEqualToString:@"ofa"] || [deviceType isEqualToString:@"ifa"] || [deviceType isEqualToString:@"ifc"] || [deviceType isEqualToString:@"ina"]){
        
        if ([self.lblSensor.text isEqualToString:@"Chamber Set Point"]) {
            
            plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-2) length:CPTDecimalFromInt(3000)];
            //Setup X-axis spaces
            plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-10)length:CPTDecimalFromInt(10)];
            
            
            plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-40) length:CPTDecimalFromInt(400)];
            plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(180)length:CPTDecimalFromInt(1000)];
            
        }else if ([self.lblSensor.text isEqualToString:@"High Temperature Limit"]){
            
            plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-2) length:CPTDecimalFromInt(3000)];
            //Setup X-axis spaces
            plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-10)length:CPTDecimalFromInt(10)];
            
            
            plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-200) length:CPTDecimalFromInt(500)];
            plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-90)length:CPTDecimalFromInt(1000)];
            
        }else if ([self.lblSensor.text isEqualToString:@"Low Temperature Limit"]){
            
            plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-2) length:CPTDecimalFromInt(3000)];
            //Setup X-axis spaces
            plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-10)length:CPTDecimalFromInt(10)];
            
            
            plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-200) length:CPTDecimalFromInt(500)];
            plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-90)length:CPTDecimalFromInt(1000)];
            
        }else if ([self.lblSensor.text isEqualToString:@"Chamber Temperature Sensor"]){
            
            plotSpace.globalXRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-2) length:CPTDecimalFromInt(3000)];
            //Setup X-axis spaces
            plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-10)length:CPTDecimalFromInt(10)];
            
            
            plotSpace.globalYRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-200) length:CPTDecimalFromInt(500)];
            plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-90)length:CPTDecimalFromInt(1000)];
            
        }
    }
    
    
    
    
    
    
    
    //Trial

    
//    
//    CPTMutablePlotRange *xRange = [plotSpace.xRange mutableCopy];
//	[xRange expandRangeByFactor:CPTDecimalFromCGFloat(0.8f)];
//	plotSpace.xRange = xRange;
//	CPTMutablePlotRange *yRange = [plotSpace.yRange mutableCopy];
//	[yRange expandRangeByFactor:CPTDecimalFromCGFloat(10.5f)];
//	plotSpace.yRange = yRange;
//    
    
	
    
    // 4 - Create styles and symbols
	CPTMutableLineStyle *aaplLineStyle = [aaplPlot.dataLineStyle mutableCopy];
	aaplLineStyle.lineWidth = 2.5;
	aaplLineStyle.lineColor = aaplColor;
	aaplPlot.dataLineStyle = aaplLineStyle;
	CPTMutableLineStyle *aaplSymbolLineStyle = [CPTMutableLineStyle lineStyle];
	aaplSymbolLineStyle.lineColor = aaplColor;
	CPTPlotSymbol *aaplSymbol = [CPTPlotSymbol ellipsePlotSymbol];
	aaplSymbol.fill = [CPTFill fillWithColor:aaplColor];
	aaplSymbol.lineStyle = aaplSymbolLineStyle;
	aaplSymbol.size = CGSizeMake(6.0f, 6.0f);
	aaplPlot.plotSymbol = aaplSymbol;
    //	CPTMutableLineStyle *googLineStyle = [googPlot.dataLineStyle mutableCopy];
    //	googLineStyle.lineWidth = 1.0;
    //	googLineStyle.lineColor = googColor;
    //	googPlot.dataLineStyle = googLineStyle;
    //	CPTMutableLineStyle *googSymbolLineStyle = [CPTMutableLineStyle lineStyle];
    //	googSymbolLineStyle.lineColor = googColor;
    //	CPTPlotSymbol *googSymbol = [CPTPlotSymbol starPlotSymbol];
    //	googSymbol.fill = [CPTFill fillWithColor:googColor];
    //	googSymbol.lineStyle = googSymbolLineStyle;
    //	googSymbol.size = CGSizeMake(6.0f, 6.0f);
    //	googPlot.plotSymbol = googSymbol;
	CPTMutableLineStyle *msftLineStyle = [msftPlot.dataLineStyle mutableCopy];
	msftLineStyle.lineWidth = 2.0;
	msftLineStyle.lineColor = msftColor;
	msftPlot.dataLineStyle = msftLineStyle;
	CPTMutableLineStyle *msftSymbolLineStyle = [CPTMutableLineStyle lineStyle];
	msftSymbolLineStyle.lineColor = msftColor;
	CPTPlotSymbol *msftSymbol = [CPTPlotSymbol diamondPlotSymbol];
	msftSymbol.fill = [CPTFill fillWithColor:msftColor];
	msftSymbol.lineStyle = msftSymbolLineStyle;
	msftSymbol.size = CGSizeMake(6.0f, 6.0f);
	msftPlot.plotSymbol = msftSymbol;
}

-(void)configureAxes {
	// 1 - Create styles
	CPTMutableTextStyle *axisTitleStyle = [CPTMutableTextStyle textStyle];
	axisTitleStyle.color = [CPTColor whiteColor];
	axisTitleStyle.fontName = @"Helvetica-Bold";
	axisTitleStyle.fontSize = 12.0f;
	CPTMutableLineStyle *axisLineStyle = [CPTMutableLineStyle lineStyle];
	axisLineStyle.lineWidth = 2.0f;
	axisLineStyle.lineColor = [CPTColor whiteColor];
	CPTMutableTextStyle *axisTextStyle = [[CPTMutableTextStyle alloc] init];
	axisTextStyle.color = [CPTColor whiteColor];
	axisTextStyle.fontName = @"Helvetica-Bold";
	axisTextStyle.fontSize = 11.0f;
    
	CPTMutableLineStyle *tickLineStyle = [CPTMutableLineStyle lineStyle];
	tickLineStyle.lineColor = [CPTColor whiteColor];
	tickLineStyle.lineWidth = 2.0f;
	CPTMutableLineStyle *gridLineStyle = [CPTMutableLineStyle lineStyle];
	tickLineStyle.lineColor = [CPTColor blackColor];
	tickLineStyle.lineWidth = 1.0f;
	
    
    
    // 2 - Get axis set
	CPTXYAxisSet *axisSet = (CPTXYAxisSet *) self.hostView.hostedGraph.axisSet;
    
	// 3 - Configure x-axis
	CPTAxis *x = axisSet.xAxis;
    
    //Default Setup
    
//	x.title = @"Time And Date";
//	x.titleTextStyle = axisTitleStyle;
//	x.titleOffset = -18.0f;
//	x.axisLineStyle = axisLineStyle;
//	x.labelingPolicy = CPTAxisLabelingPolicyNone;
//	x.labelTextStyle = axisTextStyle;
//	x.majorTickLineStyle = axisLineStyle;
//	x.majorTickLength = -4.0f;
//	x.tickDirection = CPTSignNegative;
	
//	x.axisLabels = xLabelsPos;
//	x.majorTickLocations = xLocationsPos;
    
    
    
    
    x.title = @"Time And Date";
	x.titleTextStyle = axisTitleStyle;
	x.titleOffset = -18.0f;
	x.axisLineStyle = axisLineStyle;
	x.labelingPolicy = CPTAxisLabelingPolicyNone;
	x.labelTextStyle = axisTextStyle;
	x.majorTickLineStyle = axisLineStyle;
	x.majorTickLength = 4.0f;
	x.tickDirection = CPTSignNegative;
    
    
    
    
    CGFloat dateCountPos = [[[CPDStockPriceStore sharedInstance] datesInMonth] count];
	NSMutableSet *xLabelsPos = [NSMutableSet setWithCapacity:dateCountPos];
	NSMutableSet *xLocationsPos = [NSMutableSet setWithCapacity:dateCountPos];
	NSInteger iPos = 0;
	for (NSString *datePos in [[CPDStockPriceStore sharedInstance] datesInMonth]) {
		CPTAxisLabel *labelPos = [[CPTAxisLabel alloc] initWithText:datePos  textStyle:x.labelTextStyle];
		CGFloat locationPos = iPos++;
		labelPos.tickLocation = CPTDecimalFromCGFloat(locationPos);
		labelPos.offset = x.majorTickLength;
        labelPos.rotation = M_PI/4;
		if (labelPos) {
			[xLabelsPos addObject:labelPos];
			[xLocationsPos addObject:[NSNumber numberWithFloat:locationPos]];
		}
	}
    
    
    
    
	CGFloat dateCount = [[[CPDStockPriceStore sharedInstance] datesInMonth] count];
	NSMutableSet *xLabels = [NSMutableSet setWithCapacity:dateCount];
	NSMutableSet *xLocations = [NSMutableSet setWithCapacity:dateCount];
	NSInteger i = 0;
	for (NSString *date in [[CPDStockPriceStore sharedInstance] datesInMonth]) {
		CPTAxisLabel *label = [[CPTAxisLabel alloc] initWithText:date  textStyle:x.labelTextStyle];
		CGFloat location = i++;
		label.tickLocation = CPTDecimalFromCGFloat(location);
		label.offset = -85;
        label.rotation = M_PI/4;
        label.alignment = -2.0f;
		if (label) {
			[xLabels addObject:label];
			[xLocations addObject:[NSNumber numberWithFloat:location]];
		}
	}
    
//	x.axisLabels = xLabels;
//	x.majorTickLocations = xLocations;
    
    
    
	// 4 - Configure y-axis
	CPTAxis *y = axisSet.yAxis;
    
	y.title = @"Degrees";
	y.titleTextStyle = axisTitleStyle;
	y.titleOffset = -40.0f;
	y.axisLineStyle = axisLineStyle;
	y.majorGridLineStyle = gridLineStyle;
    
    
	y.labelingPolicy = CPTAxisLabelingPolicyNone;
	y.labelTextStyle = axisTextStyle;
	y.labelOffset = 16.0f;
	y.majorTickLineStyle = axisLineStyle;
	y.majorTickLength = 2.0f;
	y.minorTickLength = 1.0f;
	y.tickDirection = CPTSignNone;
    
    
    //Positive Plot
    
    NSInteger majorIncrementPos = 5;
	NSInteger minorIncrementPos = 50;
	CGFloat yMaxPos = 300.0f;  // should determine dynamically based on max price
	NSMutableSet *yLabelsPos = [NSMutableSet set];
	NSMutableSet *yMajorLocationsPos = [NSMutableSet set];
	NSMutableSet *yMinorLocationsPos = [NSMutableSet set];
    
	for (NSInteger jPos = minorIncrementPos; jPos <= yMaxPos; jPos += minorIncrementPos) {
		NSUInteger modPos = jPos % majorIncrementPos;
        NSLog(@"Test mod %i",modPos);
        
		if (modPos == 0) {
			CPTAxisLabel *labelPos = [[CPTAxisLabel alloc] initWithText:[NSString stringWithFormat:@"%i", jPos] textStyle:y.labelTextStyle];
			NSDecimal locationPos = CPTDecimalFromInteger(jPos);
			labelPos.tickLocation = locationPos;
			labelPos.offset = -y.majorTickLength - y.labelOffset;
            
            
			if (labelPos) {
				[yLabelsPos addObject:labelPos];
                
			}
			[yMajorLocationsPos addObject:[NSDecimalNumber decimalNumberWithDecimal:locationPos]];
		} else {
			[yMinorLocationsPos addObject:[NSDecimalNumber decimalNumberWithDecimal:CPTDecimalFromInteger(jPos)]];
		}
	}
    
    
    // Negative Plot
    
    
	NSInteger majorIncrement = -5;
	NSInteger minorIncrement = -50;
	CGFloat yMax = -300.0f;  // should determine dynamically based on max price
	NSMutableSet *yLabels = [NSMutableSet set];
	NSMutableSet *yMajorLocations = [NSMutableSet set];
	NSMutableSet *yMinorLocations = [NSMutableSet set];
    
	for (NSInteger j = minorIncrement; j >= yMax; j += minorIncrement) {
		NSUInteger mod = j % majorIncrement;
        NSLog(@"Test mod %i",mod);
        
		if (mod == 0) {
			CPTAxisLabel *label = [[CPTAxisLabel alloc] initWithText:[NSString stringWithFormat:@"%i", j] textStyle:y.labelTextStyle];
			NSDecimal location = CPTDecimalFromInteger(j);
			label.tickLocation = location;
			label.offset = -y.majorTickLength - y.labelOffset;
            
            
			if (label) {
				[yLabels addObject:label];
                
			}
			[yMajorLocations addObject:[NSDecimalNumber decimalNumberWithDecimal:location]];
		} else {
			[yMinorLocations addObject:[NSDecimalNumber decimalNumberWithDecimal:CPTDecimalFromInteger(j)]];
		}
	}
    
    NSLog(@"Test Sensor Type %@",self.lblSensor.text);
//
    
    
    
    
//    y.axisLabels = yLabels;
//    
//    y.majorTickLocations = yMajorLocations;
//    y.minorTickLocations = yMinorL
    
    deviceType = [[ParserClass sharedItems] equipmentType];
    
    
    if ([deviceType isEqualToString:@"ultf_gold"] || [deviceType isEqualToString:@"ultf_silver"]) {
        
        if ([self.lblSensor.text isEqualToString:@"Chamber Set Point"]) {
            
            
            x.axisLabels = xLabelsPos;
            x.majorTickLocations = xLocationsPos;
            [x setNeedsRelabel];
            
            y.axisLabels = yLabelsPos;
            y.majorTickLocations = yMajorLocationsPos;
            y.minorTickLocations = yMinorLocationsPos;
            [y setNeedsRelabel];
            
        }else if ([self.lblSensor.text isEqualToString:@"High Temperature Limit"]){
            
            x.axisLabels = xLabels;
            x.majorTickLocations = xLocations;
            [x setNeedsRelabel];
            
            y.axisLabels = yLabels;
            y.majorTickLocations = yMajorLocations;
            y.minorTickLocations = yMinorLocations;
            [y setNeedsRelabel];
            
        }else if ([self.lblSensor.text isEqualToString:@"Low Temperature Limit"]){
            
            x.axisLabels = xLabels;
            x.majorTickLocations = xLocations;
            [x setNeedsRelabel];
            
            y.axisLabels = yLabels;
            y.majorTickLocations = yMajorLocations;
            y.minorTickLocations = yMinorLocations;
            [y setNeedsRelabel];
            
        }else if ([self.lblSensor.text isEqualToString:@"Chamber Temperature Sensor"]){
            
            x.axisLabels = xLabels;
            x.majorTickLocations = xLocations;
            [x setNeedsRelabel];
            
            y.axisLabels = yLabels;
            y.majorTickLocations = yMajorLocations;
            y.minorTickLocations = yMinorLocations;
            [y setNeedsRelabel];
            
        }else if ([self.lblSensor.text isEqualToString:@"NTC Ambient Sensor"]){
            
            x.axisLabels = xLabelsPos;
            x.majorTickLocations = xLocationsPos;
            [x setNeedsRelabel];
            
            y.axisLabels = yLabelsPos;
            y.majorTickLocations = yMajorLocationsPos;
            y.minorTickLocations = yMinorLocationsPos;
            [y setNeedsRelabel];
            
        }else if ([self.lblSensor.text isEqualToString:@"NTC Condenser Sensor"]){
            
            x.axisLabels = xLabelsPos;
            x.majorTickLocations = xLocationsPos;
            [x setNeedsRelabel];
            
            y.axisLabels = yLabelsPos;
            y.majorTickLocations = yMajorLocationsPos;
            y.minorTickLocations = yMinorLocationsPos;
            [y setNeedsRelabel];
            
        }else if ([self.lblSensor.text isEqualToString:@"NTC Heat Exchanger 1"]){
            
            x.axisLabels = xLabels;
            x.majorTickLocations = xLocations;
            [x setNeedsRelabel];
            
            y.axisLabels = yLabels;
            y.majorTickLocations = yMajorLocations;
            y.minorTickLocations = yMinorLocations;
            [y setNeedsRelabel];
            
        }else if ([self.lblSensor.text isEqualToString:@"NTC Heat Exchanger 2"]){
            
            x.axisLabels = xLabels;
            x.majorTickLocations = xLocations;
            [x setNeedsRelabel];
            
            y.axisLabels = yLabels;
            y.majorTickLocations = yMajorLocations;
            y.minorTickLocations = yMinorLocations;
            [y setNeedsRelabel];
            
        }else if ([self.lblSensor.text isEqualToString:@"AC Voltage"]){
            
            x.axisLabels = xLabels;
            x.majorTickLocations = xLocations;
            [x setNeedsRelabel];
            
            y.axisLabels = yLabels;
            y.majorTickLocations = yMajorLocations;
            y.minorTickLocations = yMinorLocations;
            [y setNeedsRelabel];
            
        }
        
    }else if ([deviceType isEqualToString:@"ultf_platinum"]){
        
        if ([self.lblSensor.text isEqualToString:@"Chamber Set Point"]) {
            
            x.axisLabels = xLabels;
            x.majorTickLocations = xLocations;
            [x setNeedsRelabel];
            
            y.axisLabels = yLabels;
            y.majorTickLocations = yMajorLocations;
            y.minorTickLocations = yMinorLocations;
            [y setNeedsRelabel];
            
        }else if ([self.lblSensor.text isEqualToString:@"High Temperature Limit"]){
            
            x.axisLabels = xLabels;
            x.majorTickLocations = xLocations;
            [x setNeedsRelabel];
            
            y.axisLabels = yLabels;
            y.majorTickLocations = yMajorLocations;
            y.minorTickLocations = yMinorLocations;
            [y setNeedsRelabel];
            
        }else if ([self.lblSensor.text isEqualToString:@"Low Temperature Limit"]){
            
            x.axisLabels = xLabels;
            x.majorTickLocations = xLocations;
            [x setNeedsRelabel];
            
            y.axisLabels = yLabels;
            y.majorTickLocations = yMajorLocations;
            y.minorTickLocations = yMinorLocations;
            [y setNeedsRelabel];
            
        }else if ([self.lblSensor.text isEqualToString:@"Chamber Temperature Sensor"]){
            
            x.axisLabels = xLabels;
            x.majorTickLocations = xLocations;
            [x setNeedsRelabel];
            
            y.axisLabels = yLabels;
            y.majorTickLocations = yMajorLocations;
            y.minorTickLocations = yMinorLocations;
            [y setNeedsRelabel];
            
        }else if ([self.lblSensor.text isEqualToString:@"Ambient Sensor"]){
            
            x.axisLabels = xLabelsPos;
            x.majorTickLocations = xLocationsPos;
            [x setNeedsRelabel];
            
            y.axisLabels = yLabelsPos;
            y.majorTickLocations = yMajorLocationsPos;
            y.minorTickLocations = yMinorLocationsPos;
            [y setNeedsRelabel];
            
        }else if ([self.lblSensor.text isEqualToString:@"Condenser Outlet Sensor"]){
            
            x.axisLabels = xLabelsPos;
            x.majorTickLocations = xLocationsPos;
            [x setNeedsRelabel];
            
            y.axisLabels = yLabelsPos;
            y.majorTickLocations = yMajorLocationsPos;
            y.minorTickLocations = yMinorLocationsPos;
            [y setNeedsRelabel];
            
        }else if ([self.lblSensor.text isEqualToString:@"Heat Exchanger Temperature Sensor"]){
            
            x.axisLabels = xLabels;
            x.majorTickLocations = xLocations;
            [x setNeedsRelabel];
            
            y.axisLabels = yLabels;
            y.majorTickLocations = yMajorLocations;
            y.minorTickLocations = yMinorLocations;
            [y setNeedsRelabel];
            
        }else if ([self.lblSensor.text isEqualToString:@"Evap In Sensor"]){
            
            x.axisLabels = xLabels;
            x.majorTickLocations = xLocations;
            [x setNeedsRelabel];
            
            y.axisLabels = yLabels;
            y.majorTickLocations = yMajorLocations;
            y.minorTickLocations = yMinorLocations;
            [y setNeedsRelabel];
            
        }else if ([self.lblSensor.text isEqualToString:@"Evap Out Sensor"]){
            
            x.axisLabels = xLabels;
            x.majorTickLocations = xLocations;
            [x setNeedsRelabel];
            
            y.axisLabels = yLabels;
            y.majorTickLocations = yMajorLocations;
            y.minorTickLocations = yMinorLocations;
            [y setNeedsRelabel];
            
        }else if ([self.lblSensor.text isEqualToString:@"Battery Voltage"]){
            
            x.axisLabels = xLabelsPos;
            x.majorTickLocations = xLocationsPos;
            [x setNeedsRelabel];
            
            y.axisLabels = yLabelsPos;
            y.majorTickLocations = yMajorLocationsPos;
            y.minorTickLocations = yMinorLocationsPos;
            [y setNeedsRelabel];
            
        }else if ([self.lblSensor.text isEqualToString:@"AC Voltage"]){
            
            x.axisLabels = xLabelsPos;
            x.majorTickLocations = xLocationsPos;
            [x setNeedsRelabel];
            
            y.axisLabels = yLabelsPos;
            y.majorTickLocations = yMajorLocationsPos;
            y.minorTickLocations = yMinorLocationsPos;
            [y setNeedsRelabel];
            
        }else if ([self.lblSensor.text isEqualToString:@"High Stage"]){
            
            y.axisLabels = yLabelsPos;
            y.majorTickLocations = yMajorLocationsPos;
            y.minorTickLocations = yMinorLocationsPos;
            [y setNeedsRelabel];
            
        }
        
    }else if ([deviceType isEqualToString:@"co2_incubator"]){
        
        
        if ([self.lblSensor.text isEqualToString:@"Temperature Set Point"]) {
            
            x.axisLabels = xLabelsPos;
            x.majorTickLocations = xLocationsPos;
            [x setNeedsRelabel];
            
            y.axisLabels = yLabelsPos;
            y.majorTickLocations = yMajorLocationsPos;
            y.minorTickLocations = yMinorLocationsPos;
            [y setNeedsRelabel];
            
        }else if ([self.lblSensor.text isEqualToString:@"Co2 Set Point"]){
            
            x.axisLabels = xLabels;
            x.majorTickLocations = xLocations;
            [x setNeedsRelabel];
            
            y.axisLabels = yLabels;
            y.majorTickLocations = yMajorLocations;
            y.minorTickLocations = yMinorLocations;
            [y setNeedsRelabel];
            
        }else if ([self.lblSensor.text isEqualToString:@"O2 Set Point"]){
            
            x.axisLabels = xLabels;
            x.majorTickLocations = xLocations;
            [x setNeedsRelabel];
            
            y.axisLabels = yLabels;
            y.majorTickLocations = yMajorLocations;
            y.minorTickLocations = yMinorLocations;
            [y setNeedsRelabel];
            
        }else if ([self.lblSensor.text isEqualToString:@"High Temperature Limit"]){
            
            x.axisLabels = xLabels;
            x.majorTickLocations = xLocations;
            [x setNeedsRelabel];
            
            y.axisLabels = yLabels;
            y.majorTickLocations = yMajorLocations;
            y.minorTickLocations = yMinorLocations;
            [y setNeedsRelabel];
            
        }else if ([self.lblSensor.text isEqualToString:@"Low Temperature Limit"]){
            
            x.axisLabels = xLabelsPos;
            x.majorTickLocations = xLocationsPos;
            [x setNeedsRelabel];
            
            y.axisLabels = yLabelsPos;
            y.majorTickLocations = yMajorLocationsPos;
            y.minorTickLocations = yMinorLocationsPos;
            [y setNeedsRelabel];
            
        }else if ([self.lblSensor.text isEqualToString:@"High Co2 Limit"]){
            
            x.axisLabels = xLabelsPos;
            x.majorTickLocations = xLocationsPos;
            [x setNeedsRelabel];
            
            y.axisLabels = yLabelsPos;
            y.majorTickLocations = yMajorLocationsPos;
            y.minorTickLocations = yMinorLocationsPos;
            [y setNeedsRelabel];
            
        }else if ([self.lblSensor.text isEqualToString:@"Low Co2 Limit"]){
            
            x.axisLabels = xLabels;
            x.majorTickLocations = xLocations;
            [x setNeedsRelabel];
            
            y.axisLabels = yLabels;
            y.majorTickLocations = yMajorLocations;
            y.minorTickLocations = yMinorLocations;
            [y setNeedsRelabel];
            
        }else if ([self.lblSensor.text isEqualToString:@"High O2 Limit"]){
            
            x.axisLabels = xLabels;
            x.majorTickLocations = xLocations;
            [x setNeedsRelabel];
            
            y.axisLabels = yLabels;
            y.majorTickLocations = yMajorLocations;
            y.minorTickLocations = yMinorLocations;
            [y setNeedsRelabel];
            
        }else if ([self.lblSensor.text isEqualToString:@"Low O2 Limit"]){
            
            x.axisLabels = xLabels;
            x.majorTickLocations = xLocations;
            [x setNeedsRelabel];
            
            y.axisLabels = yLabels;
            y.majorTickLocations = yMajorLocations;
            y.minorTickLocations = yMinorLocations;
            [y setNeedsRelabel];
            
        }else if ([self.lblSensor.text isEqualToString:@"Low Rh Limit"]){
         
            x.axisLabels = xLabelsPos;
            x.majorTickLocations = xLocationsPos;
            [x setNeedsRelabel];
            
            y.axisLabels = yLabelsPos;
            y.majorTickLocations = yMajorLocationsPos;
            y.minorTickLocations = yMinorLocationsPos;
            [y setNeedsRelabel];
            
        }else if ([self.lblSensor.text isEqualToString:@"Temperature Sensor"]){
            
            x.axisLabels = xLabelsPos;
            x.majorTickLocations = xLocationsPos;
            [x setNeedsRelabel];
            
            y.axisLabels = yLabelsPos;
            y.majorTickLocations = yMajorLocationsPos;
            y.minorTickLocations = yMinorLocationsPos;
            [y setNeedsRelabel];
            
        }else if ([self.lblSensor.text isEqualToString:@"Co2 Sensor"]){
            
            x.axisLabels = xLabelsPos;
            x.majorTickLocations = xLocationsPos;
            [x setNeedsRelabel];
            
            y.axisLabels = yLabelsPos;
            y.majorTickLocations = yMajorLocationsPos;
            y.minorTickLocations = yMinorLocationsPos;
            [y setNeedsRelabel];
            
        }else if ([self.lblSensor.text isEqualToString:@"o2 Sensor"]){
            
            x.axisLabels = xLabelsPos;
            x.majorTickLocations = xLocationsPos;
            [x setNeedsRelabel];
            
            y.axisLabels = yLabelsPos;
            y.majorTickLocations = yMajorLocationsPos;
            y.minorTickLocations = yMinorLocationsPos;
            [y setNeedsRelabel];
            
        }else if ([self.lblSensor.text isEqualToString:@"Rh Sensor"]){
            
            x.axisLabels = xLabelsPos;
            x.majorTickLocations = xLocationsPos;
            [x setNeedsRelabel];
            
            y.axisLabels = yLabelsPos;
            y.majorTickLocations = yMajorLocationsPos;
            y.minorTickLocations = yMinorLocationsPos;
            [y setNeedsRelabel];
            
        }
        
    }else if ([deviceType isEqualToString:@"ecs-g2"]){
        
        
        if ([self.lblSensor.text isEqualToString:@"Low Inflow Limit"]) {
            
            x.axisLabels = xLabelsPos;
            x.majorTickLocations = xLocationsPos;
            [x setNeedsRelabel];
            
            y.axisLabels = yLabelsPos;
            y.majorTickLocations = yMajorLocationsPos;
            y.minorTickLocations = yMinorLocationsPos;
            [y setNeedsRelabel];
            
        }else if ([self.lblSensor.text isEqualToString:@"High Downflow Limit"]){
            
            x.axisLabels = xLabels;
            x.majorTickLocations = xLocations;
            [x setNeedsRelabel];
            
            y.axisLabels = yLabels;
            y.majorTickLocations = yMajorLocations;
            y.minorTickLocations = yMinorLocations;
            [y setNeedsRelabel];
            
        }else if ([self.lblSensor.text isEqualToString:@"Low Downflow Limit"]){
            
            x.axisLabels = xLabels;
            x.majorTickLocations = xLocations;
            [x setNeedsRelabel];
            
            y.axisLabels = yLabels;
            y.majorTickLocations = yMajorLocations;
            y.minorTickLocations = yMinorLocations;
            [y setNeedsRelabel];
            
        }else if ([self.lblSensor.text isEqualToString:@"High Temperature Limit"]){
            
            x.axisLabels = xLabels;
            x.majorTickLocations = xLocations;
            [x setNeedsRelabel];
            
            y.axisLabels = yLabels;
            y.majorTickLocations = yMajorLocations;
            y.minorTickLocations = yMinorLocations;
            [y setNeedsRelabel];
            
        }else if ([self.lblSensor.text isEqualToString:@"Low Temperature Limit"]){
            
            x.axisLabels = xLabelsPos;
            x.majorTickLocations = xLocationsPos;
            [x setNeedsRelabel];
            
            y.axisLabels = yLabelsPos;
            y.majorTickLocations = yMajorLocationsPos;
            y.minorTickLocations = yMinorLocationsPos;
            [y setNeedsRelabel];
            
        }else if ([self.lblSensor.text isEqualToString:@"High DC Voltage Limit"]){
            
            x.axisLabels = xLabelsPos;
            x.majorTickLocations = xLocationsPos;
            [x setNeedsRelabel];
            
            y.axisLabels = yLabelsPos;
            y.majorTickLocations = yMajorLocationsPos;
            y.minorTickLocations = yMinorLocationsPos;
            [y setNeedsRelabel];
            
        }else if ([self.lblSensor.text isEqualToString:@"Low DC Voltage Limit"]){
            
            x.axisLabels = xLabels;
            x.majorTickLocations = xLocations;
            [x setNeedsRelabel];
            
            y.axisLabels = yLabels;
            y.majorTickLocations = yMajorLocations;
            y.minorTickLocations = yMinorLocations;
            [y setNeedsRelabel];
            
        }else if ([self.lblSensor.text isEqualToString:@"Inflow Sensor"]){
            
            x.axisLabels = xLabels;
            x.majorTickLocations = xLocations;
            [x setNeedsRelabel];
            
            y.axisLabels = yLabels;
            y.majorTickLocations = yMajorLocations;
            y.minorTickLocations = yMinorLocations;
            [y setNeedsRelabel];
            
        }else if ([self.lblSensor.text isEqualToString:@"Downflow Sensor"]){
            
            
            x.axisLabels = xLabels;
            x.majorTickLocations = xLocations;
            [x setNeedsRelabel];
            
            y.axisLabels = yLabels;
            y.majorTickLocations = yMajorLocations;
            y.minorTickLocations = yMinorLocations;
            [y setNeedsRelabel];
            
        }else if ([self.lblSensor.text isEqualToString:@"Temperature Sensor"]){
            
            x.axisLabels = xLabelsPos;
            x.majorTickLocations = xLocationsPos;
            [x setNeedsRelabel];
            
            y.axisLabels = yLabelsPos;
            y.majorTickLocations = yMajorLocationsPos;
            y.minorTickLocations = yMinorLocationsPos;
            [y setNeedsRelabel];
            
        }else if ([self.lblSensor.text isEqualToString:@"DC Voltage"]){
            
            x.axisLabels = xLabelsPos;
            x.majorTickLocations = xLocationsPos;
            [x setNeedsRelabel];
            
            y.axisLabels = yLabelsPos;
            y.majorTickLocations = yMajorLocationsPos;
            y.minorTickLocations = yMinorLocationsPos;
            [y setNeedsRelabel];
            
        }
        
    }else if ([deviceType isEqualToString:@"ofa"] || [deviceType isEqualToString:@"ifa"] || [deviceType isEqualToString:@"ifc"] || [deviceType isEqualToString:@"ina"]){
        
        if ([self.lblSensor.text isEqualToString:@"Chamber Set Point"]) {
            
            x.axisLabels = xLabelsPos;
            x.majorTickLocations = xLocationsPos;
            [x setNeedsRelabel];
            
            y.axisLabels = yLabelsPos;
            y.majorTickLocations = yMajorLocationsPos;
            y.minorTickLocations = yMinorLocationsPos;
            [y setNeedsRelabel];
            
        }else if ([self.lblSensor.text isEqualToString:@"High Temperature Limit"]){
            
            x.axisLabels = xLabels;
            x.majorTickLocations = xLocations;
            [x setNeedsRelabel];
            
            y.axisLabels = yLabels;
            y.majorTickLocations = yMajorLocations;
            y.minorTickLocations = yMinorLocations;
            [y setNeedsRelabel];
            
        }else if ([self.lblSensor.text isEqualToString:@"Low Temperature Limit"]){
            
            x.axisLabels = xLabels;
            x.majorTickLocations = xLocations;
            [x setNeedsRelabel];
            
            y.axisLabels = yLabels;
            y.majorTickLocations = yMajorLocations;
            y.minorTickLocations = yMinorLocations;
            [y setNeedsRelabel];
            
        }else if ([self.lblSensor.text isEqualToString:@"Chamber Temperature Sensor"]){
            
            x.axisLabels = xLabels;
            x.majorTickLocations = xLocations;
            [x setNeedsRelabel];
            
            y.axisLabels = yLabels;
            y.majorTickLocations = yMajorLocations;
            y.minorTickLocations = yMinorLocations;
            [y setNeedsRelabel];
            
        }
    }
    
}



#pragma mark - Rotation
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}

#pragma mark - CPTPlotDataSource methods
-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot {
	return [[[CPDStockPriceStore sharedInstance] datesInMonth] count];
}

-(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index {
	NSInteger valueCount = [[[CPDStockPriceStore sharedInstance] datesInMonth] count];
	switch (fieldEnum) {
		case CPTScatterPlotFieldX:
			if (index < valueCount) {
				return [NSNumber numberWithUnsignedInteger:index];
			}
			break;
			
		case CPTScatterPlotFieldY:
			if ([plot.identifier isEqual:CPDTickerSymbolAAPL] == YES) {
				return [[[CPDStockPriceStore sharedInstance] monthlyPrices:CPDTickerSymbolAAPL] objectAtIndex:index];
			} else if ([plot.identifier isEqual:CPDTickerSymbolGOOG] == YES) {
				return [[[CPDStockPriceStore sharedInstance] monthlyPrices:CPDTickerSymbolGOOG] objectAtIndex:index];
			} else if ([plot.identifier isEqual:CPDTickerSymbolMSFT] == YES) {
				return [[[CPDStockPriceStore sharedInstance] monthlyPrices:CPDTickerSymbolMSFT] objectAtIndex:index];
			}
			break;
	}
	return [NSDecimalNumber zero];
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscape;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationLandscapeRight;
}

-(BOOL)shouldAutorotate{
    
    return NO;
}


- (IBAction)btnBack:(id)sender {
    
//   DevicesTableViewController *devMain = [[DevicesTableViewController alloc]initWithNibName:@"DevicesTableViewController" bundle:nil];
    
   // [self.navigationController dismissViewControllerAnimated:YES completion:nil];
    
    //[[UiManager sharedItems].deckController dismissViewControllerAnimated:YES completion:nil];
    
   // [[UiManager sharedItems].deckController dismissViewControllerAnimated:YES completion:nil];
    
   // [self.navigationController popViewControllerAnimated:YES];
    
    //[self dismissViewControllerAnimated:YES completion:nil];
    
//    [self dismissViewControllerAnimated:YES completion:nil];
  
 //   [self.navigationController dismissViewControllerAnimated:YES completion:nil];
    
   // [[UiManager sharedItems].devicesTableView.delegate dismissGraph];
    
    [self dismissViewControllerAnimated:YES completion:nil];
    NSLog(@"Click");
    
}

- (void)dismissGraph{
    
    NSLog(@"Dismiss this please");

    [[UiManager sharedItems].loginView dismissViewControllerAnimated:YES completion:nil];
}

- (IBAction)btnFilter:(id)sender {
    
    [self.view addSubview:self.viewFilters];
    
    [self.viewFilters setAlpha:0];
    
    [UIView animateWithDuration:0.5 animations:^{
        
    [self.viewFilters setAlpha:1.0];
    
    }completion:^(BOOL finished){
        
    
    }];
    
    
}

- (IBAction)btnCancel:(id)sender {
    
    [UIView animateWithDuration:0.5 animations:^{
        
        [self.viewFilters setAlpha:0];
        
    }completion:^(BOOL finished){
        [self.viewFilters removeFromSuperview];
        
    }];
}

- (IBAction)btnSensor:(id)sender {
    if (state == 1) {
        
        [self.viewToolBar setFrame:CGRectMake(96, 100, 388, 152)];
        [self.viewToolBar setAlpha:0.0];
        [self.viewFilters addSubview:self.viewToolBar];
        [self.viewToolBar setAlpha:0.0];
        [UIView animateWithDuration:0.5 animations:^{
            
            [self.viewToolBar setFrame:CGRectMake(96, 100, 388, 152)];
            
            [self.viewToolBar setAlpha:1.0];
            [self.viewFilterList setAlpha:0];
            [self.btnCancelCir setAlpha:0];
            
            arrState = 0;
            pickerCount = [sensorPicker count];
            [self.pickerViewProp reloadAllComponents];
        }completion:^(BOOL finished){
            
            
            state = 2;
        }];
        
        //NSLog(@"test %i",test);
        
    }else if (state == 2){
        
        [self.viewToolBar setFrame:CGRectMake(96, 100, 388, 152)];
        [self.viewToolBar setAlpha:1.0];
        [self.btnCancelCir setAlpha:1];
        
        [UIView animateWithDuration:0.5 animations:^{
            
            [self.viewToolBar setFrame:CGRectMake(96, 100, 388, 152)];
            [self.viewToolBar setAlpha:0.0];
            [self.viewFilterList setAlpha:1];
        }completion:^(BOOL finished){
            [self.viewToolBar removeFromSuperview];
            state = 1;
        }];
        
        //NSLog(@"test %i",test);
    }
    
    
}

- (IBAction)btnFrom:(id)sender {
    
    if (state == 1) {
        
        [self.datepickerFromandTo setFrame:CGRectMake(96, 100, 388, 152)];
        [self.datepickerFromandTo setAlpha:0.0];
        [self.viewFilters addSubview:self.datepickerFromandTo];
        [self.datepickerFromandTo setAlpha:0.0];
        [UIView animateWithDuration:0.5 animations:^{
            
            [self.datepickerFromandTo setFrame:CGRectMake(96, 100, 388, 152)];
            
            [self.datepickerFromandTo setAlpha:1.0];
            [self.viewFilterList setAlpha:0];
            [self.btnCancelCir setAlpha:0];
            
            arrState = 1;
            pickerCount = [self.datePickerArr count];
            [self.pickerViewDate reloadAllComponents];
        }completion:^(BOOL finished){
            
            
            state = 2;
        }];
        
        //NSLog(@"test %i",test);
        
    }else if (state == 2){
        
        [self.datepickerFromandTo setFrame:CGRectMake(96, 100, 388, 152)];
        [self.datepickerFromandTo setAlpha:1.0];
        [self.btnCancelCir setAlpha:1];
        
        [UIView animateWithDuration:0.5 animations:^{
            
            [self.datepickerFromandTo setFrame:CGRectMake(96, 100, 388, 152)];
            [self.datepickerFromandTo setAlpha:0.0];
            [self.viewFilterList setAlpha:1];
            pickerCount = [self.datePickerArr count];
            
        }completion:^(BOOL finished){
            [self.datepickerFromandTo removeFromSuperview];
            state = 1;
        }];
        
        //NSLog(@"test %i",test);
    }
    
    datePickerState = 1;

}

- (IBAction)btnTo:(id)sender {
    if (state == 1) {
        
        [self.datepickerFromandTo setFrame:CGRectMake(96, 100, 388, 152)];
        [self.datepickerFromandTo setAlpha:0.0];
        [self.viewFilters addSubview:self.datepickerFromandTo];
        [self.datepickerFromandTo setAlpha:0.0];
        [UIView animateWithDuration:0.5 animations:^{
            
            [self.datepickerFromandTo setFrame:CGRectMake(96, 100, 388, 152)];
            
            [self.datepickerFromandTo setAlpha:1.0];
            [self.viewFilterList setAlpha:0];
            [self.btnCancelCir setAlpha:0];
            
            arrState = 1;
            pickerCount = [self.datePickerArr count];
            [self.pickerViewDate reloadAllComponents];
        }completion:^(BOOL finished){
            
            
            state = 2;
        }];
        
        //NSLog(@"test %i",test);
        
    }else if (state == 2){
        
        [self.datepickerFromandTo setFrame:CGRectMake(96, 100, 388, 152)];
        [self.datepickerFromandTo setAlpha:1.0];
        [self.btnCancelCir setAlpha:1];
        
        [UIView animateWithDuration:0.5 animations:^{
            
            [self.datepickerFromandTo setFrame:CGRectMake(96, 100, 388, 152)];
            [self.datepickerFromandTo setAlpha:0.0];
            [self.viewFilterList setAlpha:1];
            
            pickerCount = [self.datePickerArr count];
        }completion:^(BOOL finished){
            [self.datepickerFromandTo removeFromSuperview];
            state = 1;
        }];
        
        
        //NSLog(@"test %i",test);
    }
    
    datePickerState = 2;
}

- (IBAction)btnDoneFiltering:(id)sender {
    
    NSArray *xib = [[NSBundle mainBundle] loadNibNamed:@"loadingView" owner:self options:nil];
    loadingView * loading = [xib objectAtIndex:0];
    
    [loading setFrame:CGRectMake(120, -280, 93, 47)];
    
    
    [loading.imgLoading2 setAlpha:1.0];
    [loading.imgLoading setAlpha:0.0];
    
    UIView* bgLoading = [[UIView alloc] initWithFrame:CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height)];
    
    
    [bgLoading addSubview:loading];
    [bgLoading setBackgroundColor:[UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:0.8]];
    [bgLoading setFrame:self.test.bounds];
    
    [self.test addSubview:bgLoading];

    
    [UIView animateWithDuration:0.5 animations:^{
        
        [self.viewFilters setAlpha:0];
        
    }completion:^(BOOL finished){
        [self.viewFilters removeFromSuperview];
        
        
        
        [[CPDStockPriceStore sharedInstance] devicesArr:self.lblSensor.text];
        [[CPDStockPriceStore sharedInstance] devicesArrTimeFromDate:[NSString stringWithFormat:@"%i", fromCount] andToDate:[NSString stringWithFormat:@"%i",toCount]];

        
        
        dispatch_async(kBgQueue, ^{
            
            dispatch_async(dispatch_get_main_queue(), ^{
                
                
                [bgLoading removeFromSuperview];
                
                [self configureAxes];
                
                [self configurePlots];
                [self ReloadGraph];
            });
            
        });
        
        
        
        
    }];
        

}

- (IBAction)btnCancelToolBar:(id)sender {
    
    [UIView animateWithDuration:0.5 animations:^{
        
        [self.viewToolBar setFrame:CGRectMake(96, 100, 388, 152)];
        [self.viewToolBar setAlpha:0.0];
        [self.viewFilterList setAlpha:1];
        [self.btnCancelCir setAlpha:1];
        
    }completion:^(BOOL finished){
        [self.viewToolBar removeFromSuperview];
        state = 1;
    }];
}

- (IBAction)btnDoneToolBar:(id)sender {
    [UIView animateWithDuration:0.5 animations:^{
        
        [self.viewToolBar setFrame:CGRectMake(96, 100, 388, 152)];
        [self.viewToolBar setAlpha:0.0];
        [self.viewFilterList setAlpha:1];
        [self.btnCancelCir setAlpha:1];
        
    }completion:^(BOOL finished){
        [self.viewToolBar removeFromSuperview];
        
        NSString *sensorLbl = [self pickerView:self.pickerViewProp titleForRow:[self.pickerViewProp selectedRowInComponent:0] forComponent:0 ];
        
        self.lblSensor.text = sensorLbl;
        self.lblSensorIndicator.text = sensorLbl;
        
//        [[CPDStockPriceStore sharedInstance] devicesArr:self.lblSensor.text];
//        
//        [self ReloadGraph];
        state = 1;
    }];
    
}

- (IBAction)btnCancelDate:(id)sender {
    
    [UIView animateWithDuration:0.5 animations:^{
        
        [self.datepickerFromandTo setFrame:CGRectMake(96, 100, 388, 152)];
        [self.datepickerFromandTo setAlpha:0.0];
        [self.viewFilterList setAlpha:1];
        [self.btnCancelCir setAlpha:1];
        
    }completion:^(BOOL finished){
        [self.datepickerFromandTo removeFromSuperview];
        state = 1;
    }];
}

- (IBAction)btnDoneDate:(id)sender {
    
    [UIView animateWithDuration:0.5 animations:^{
        
        [self.datepickerFromandTo setFrame:CGRectMake(96, 100, 388, 152)];
        [self.datepickerFromandTo setAlpha:0.0];
        [self.viewFilterList setAlpha:1];
        [self.btnCancelCir setAlpha:1];
        
    }completion:^(BOOL finished){
        [self.viewToolBar removeFromSuperview];
        
        NSDateFormatter *formatDay = [[NSDateFormatter alloc]init];
        [formatDay setDateFormat:@"MMM dd yyyy"];
        NSString *day = [formatDay stringFromDate:self.pickerD.date];
        
        if (datePickerState == 1) {
           
            NSString *dateLbl = [self pickerView:self.pickerViewDate titleForRow:[self.pickerViewDate selectedRowInComponent:0] forComponent:0 ];
            
            self.lblFrom.text = dateLbl;
            
            fromCount = [self.pickerViewDate selectedRowInComponent:0];
            
            
            
            
        }else if (datePickerState == 2){
            
            NSString *dateLbl = [self pickerView:self.pickerViewDate titleForRow:[self.pickerViewDate selectedRowInComponent:0] forComponent:0 ];
            
            self.lblTo.text = dateLbl;
            
            toCount = [self.pickerViewDate selectedRowInComponent:0];
            
        }
        
        
        
        state = 1;
    }];
}


#pragma PickerViewSetup;

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
    return 1;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    
    if (pickerCount == 0) {
        return 0;
    }else{
    
    return pickerCount;
    }
    //[sensorPicker count];
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
    
    if (arrState == 0) {
        return sensorPicker[row];

    }else{
    
        return self.datePickerArr[row];
    }
    
}

//- (NSAttributedString *)pickerView:(UIPickerView *)pickerView attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)component
//{
//    NSString *title = sensorPicker[row];
//    NSAttributedString *attString = [[NSAttributedString alloc] initWithString:title attributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
//    
//    return attString;
//}

-(CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component{
    return 30;
}

#pragma Classes;


@end
